package com.ruoyi.project.module.whd.jiezhang;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.project.domain.YqgBarBills;
import com.ruoyi.project.domain.YqgCheckoutMethod;
import com.ruoyi.project.service.IYqgBarBillsService;
import com.ruoyi.project.service.IYqgCheckoutMethodService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 结账方式Controller
 * 
 * @author ruoyi
 * @date 2023-08-15
 */
@RestController
@RequestMapping("/whd/method")
public class WhdCheckoutMethodController extends BaseController
{
    @Autowired
    private IYqgCheckoutMethodService yqgCheckoutMethodService;
    @Autowired
    private IYqgBarBillsService yqgBarBillsService;

    /**
     * 查询结账方式列表
     */
    /*@RequiresPermissions("project:method:list")*/
    @GetMapping("/list")
    public TableDataInfo list(YqgCheckoutMethod yqgCheckoutMethod)
    {
        startPage();
        List<YqgCheckoutMethod> list = yqgCheckoutMethodService.selectYqgCheckoutMethodList(yqgCheckoutMethod);
        return getDataTable(list);
    }
  /*  @RequiresPermissions("project:method:list")*/
    @GetMapping("/listByBarBillsId")
    public TableDataInfo listByBarBillsId(YqgCheckoutMethod yqgCheckoutMethod)
    {
        //查询分段结账记录
        YqgBarBills yqgBarBills=new YqgBarBills();
        yqgBarBills.setHandState("1");
        yqgBarBills.setHandBrand(yqgCheckoutMethod.getHandBrand());
        List<YqgBarBills> barlist = yqgBarBillsService.selectYqgBarBillsList(yqgBarBills);
        if(barlist.size()>0){
            yqgCheckoutMethod.setBarBillsId(barlist.get(0).getID());
        }

        List<YqgCheckoutMethod> list = yqgCheckoutMethodService.selectYqgCheckoutMethodList(yqgCheckoutMethod);
        System.out.println("分段"+list.size());
        return getDataTable(list);
    }

    /**
     * 导出结账方式列表
     */
   /* @RequiresPermissions("project:method:export")*/
    @Log(title = "结账方式", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, YqgCheckoutMethod yqgCheckoutMethod)
    {
        List<YqgCheckoutMethod> list = yqgCheckoutMethodService.selectYqgCheckoutMethodList(yqgCheckoutMethod);
        ExcelUtil<YqgCheckoutMethod> util = new ExcelUtil<YqgCheckoutMethod>(YqgCheckoutMethod.class);
        util.exportExcel(response, list, "结账方式数据");
    }

    /**
     * 获取结账方式详细信息
     */
   /* @RequiresPermissions("project:method:query")*/
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(yqgCheckoutMethodService.selectYqgCheckoutMethodById(id));
    }

    /**
     * 新增结账方式
     */
    /*@RequiresPermissions("project:method:add")*/
    @Log(title = "结账方式", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody YqgCheckoutMethod yqgCheckoutMethod)
    {
        return toAjax(yqgCheckoutMethodService.insertYqgCheckoutMethod(yqgCheckoutMethod));
    }

    /**
     * 修改结账方式
     */
   /* @RequiresPermissions("project:method:edit")*/
    @Log(title = "结账方式", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody YqgCheckoutMethod yqgCheckoutMethod)
    {
        return toAjax(yqgCheckoutMethodService.updateYqgCheckoutMethod(yqgCheckoutMethod));
    }

    /**
     * 删除结账方式
     */
    /*@RequiresPermissions("project:method:remove")*/
    @Log(title = "结账方式", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(yqgCheckoutMethodService.deleteYqgCheckoutMethodByIds(ids));
    }
}
